package com.wind.homework.tools;

import java.io.*;
import java.net.URL;

public class PaHtml {

    public static void method(String url)throws Exception {
        InputStream inputStream;//接收字节输入流
        InputStreamReader inputStreamReader;//将字节输入流转换成字符输入流
        BufferedReader bufferedReader;//为字符输入流加缓冲
        FileOutputStream fileOutputStream;//字节输出流
        OutputStreamWriter outputStreamWriter;//将字节输出流转换成字符输出流

        URL wangzhi = new URL(url);
        inputStream = wangzhi.openStream();
        inputStreamReader = new InputStreamReader(inputStream, "utf8");
        bufferedReader = new BufferedReader(inputStreamReader);
        String s;
        File dest = new File("/Users/gaox/Desktop/url/"+url.substring(url.length()-34,url.length()-5)+"html");
        fileOutputStream = new FileOutputStream(dest);
        outputStreamWriter = new OutputStreamWriter(fileOutputStream, "utf8");
        while ((s = bufferedReader.readLine()) != null) {
            outputStreamWriter.write(s);
        }

        outputStreamWriter.close();
        fileOutputStream.close();
        bufferedReader.close();
        inputStreamReader.close();
        inputStream.close();
    }
}
